package main

import (
	"encoding/json"
	"fmt"
)

// xiaorui.cc

type Nodes2 struct {
	Order string `json:"order"`
	Attribute  string `json:"attribute"`
	DirName string `json:"dir_name"`
	BookFileId  string `json:"book_file_id"`
	Children []Nodes2 `json:"children"`
}


func  main() {

	var father1 Nodes2
	father1.Order = "1"
	father1.Attribute = "folder"
	father1.DirName = "第1.1层文件名称"

	var father2 Nodes2
	father2.Order = "2"
	father2.Attribute = "folder"
	father2.DirName = "第1.2层文件名称"

	var father3 Nodes2
	father3.Order = "3"
	father3.Attribute = "folder"
	father3.DirName = "第1.2层文件名称"

	var f3son Nodes2
	f3son.Order = "4"
	f3son.Attribute = "file"
	f3son.BookFileId = "45454454545"


	// 需要 倒着 挂载父子关系

	var childrens3 []Nodes2
	childrens3 = append(childrens3, f3son)
	father3.Children = childrens3
	var childrens2 []Nodes2
	childrens2 = append(childrens2, father3)
	father2.Children = childrens2


	var childrens1 []Nodes2
	childrens1 = append(childrens1, father2)
	father1.Children = childrens1

	fmt.Println("=====================")

	//定义 一个 可以包含任意 数据类型的 切片
	s := make([]Nodes2,0)
	s = append(s, father1)
	//s=append(s,father2)

	var son Nodes2
	son.Order = "5"
	son.Attribute = "file"
	son.BookFileId = "4545sdsdgfs4454545"
	s = append(s, son)

	// 最终 s里面 有两个 节点 元素




//	node := make([]Nodes2,0)

	fmt.Println(s)
	// map转 json
	result2, err2 := json.Marshal(s)
	if err2 != nil {
		return
	}
	fmt.Println("result2 = ", string(result2))

	fmt.Println(len(s))





}